package cn.csc.module.pay.service.funddetailslog;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.math.BigInteger;
import java.util.*;
import cn.csc.module.pay.controller.admin.funddetailslog.vo.*;
import cn.csc.module.pay.dal.dataobject.funddetailslog.PayFundDetailsLogDO;
import cn.csc.framework.common.pojo.PageResult;

import cn.csc.module.pay.convert.funddetailslog.PayFundDetailsLogConvert;
import cn.csc.module.pay.dal.mysql.funddetailslog.PayFundDetailsLogMapper;

import static cn.csc.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.csc.module.pay.enums.ErrorCodeConstants.*;

/**
 * 用户资金收支明细表记录 Service 实现类
 *
 * @author 华南城
 */
@Service
@Validated
public class PayFundDetailsLogServiceImpl implements PayFundDetailsLogService {

    @Resource
    private PayFundDetailsLogMapper fundDetailsLogMapper;

    @Override
    public BigInteger createFundDetailsLog(PayFundDetailsLogCreateReqVO createReqVO) {
        // 插入
        PayFundDetailsLogDO fundDetailsLog = PayFundDetailsLogConvert.INSTANCE.convert(createReqVO);
        fundDetailsLogMapper.insert(fundDetailsLog);
        // 返回
        return fundDetailsLog.getId();
    }

    @Override
    public void updateFundDetailsLog(PayFundDetailsLogUpdateReqVO updateReqVO) {
        // 校验存在
        validateFundDetailsLogExists(updateReqVO.getId());
        // 更新
        PayFundDetailsLogDO updateObj = PayFundDetailsLogConvert.INSTANCE.convert(updateReqVO);
        fundDetailsLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteFundDetailsLog(BigInteger id) {
        // 校验存在
        validateFundDetailsLogExists(id);
        // 删除
        fundDetailsLogMapper.deleteById(id);
    }

    private void validateFundDetailsLogExists(BigInteger id) {
        if (fundDetailsLogMapper.selectById(id) == null) {
            throw exception(FUND_DETAILS_LOG_NOT_EXISTS);
        }
    }

    @Override
    public PayFundDetailsLogDO getFundDetailsLog(BigInteger id) {
        return fundDetailsLogMapper.selectById(id);
    }

    @Override
    public List<PayFundDetailsLogDO> getFundDetailsLogList(Collection<BigInteger> ids) {
        return fundDetailsLogMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<PayFundDetailsLogDO> getFundDetailsLogPage(PayFundDetailsLogPageReqVO pageReqVO) {
        return fundDetailsLogMapper.selectPage(pageReqVO);
    }

    @Override
    public List<PayFundDetailsLogDO> getFundDetailsLogList(PayFundDetailsLogExportReqVO exportReqVO) {
        return fundDetailsLogMapper.selectList(exportReqVO);
    }

}
